﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Avatar.Model;
using AvatarHelper;

namespace Avatar.ADService
{
   public static class ADCategoryManager
    {
        /// <summary>
        /// 编辑招聘广告分类
        /// </summary>
        /// <param name="_id"></param>
        /// <param name="_name"></param>
        /// <returns></returns>
        public static bool ADCategorySave(
            Guid _id,
            string _name,
            int _height,
            int _width,
            int _column,
            int _row)
       {
           #region 入口检测

           if (string.IsNullOrEmpty(_name)) throw new Exception("广告分类名称不能为空");

           #endregion
           return DBHelper.Save<ADCategory>(
                new ADCategory(),
                ad => ad.ID == _id,
                ad => ad.CategoryName == _name,
                delegate(ADCategory _ad)
                {
                    _ad.ID = Guid.NewGuid();
                    _ad.CategoryName = _name;
                    _ad.Height = _height;
                    _ad.MaxColumn = _column;
                    _ad.MaxRow = _row;
                    _ad.Width = _width;
                    
                },
                delegate(ADCategory _ad)
                {
                    _ad.CategoryName = _name;
                    _ad.Height = _height;
                    _ad.MaxColumn = _column;
                    _ad.MaxRow = _row;
                    _ad.Width = _width;

                }, "编辑招聘广告分类出错:");
        }

        /// <summary>
        /// 获取招聘广告分类
        /// </summary>
        /// <param name="_id">广告分类ID</param>
        /// <returns></returns>
        public static ADCategory GetADCategory(Guid _id)
        {
            return DBHelper.Get<ADCategory>(ad => ad.ID == _id, "获取招聘广告分类出错:");
        }

        public static ADCategory GetADCategory(string _user)
        {
            return DBHelper.Get<ADCategory>(ad => ad.CategoryName == _user, "获取招聘广告分类出错:");
        }
        /// <summary>
       /// 获取广告分类列表
       /// </summary>
       /// <returns></returns>
        public static List<ADCategory> GetADCategory()
        {
            return DBHelper.GetAll<ADCategory>("获取招聘广告分类列表出错:");
        }

        /// <summary>
        /// 删除招聘广告分类
        /// </summary>
        /// <param name="_id"></param>
        /// <returns></returns>
        public static bool ADCategoryDelete(Guid _id)
        {
            var _ad = GetADCategory(_id);
            return DBHelper.Delete(_ad,"删除招聘广告分类出错:");
        }
    }
}
